﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace EvoAlgLib
{
    public class BinaryIndividual : GenArrayIndividual
    {
        public BinaryIndividual(double mutate)
            : base(mutate)
        {
            genotype = new int[LENGTH];
            for (int i = 0; i < LENGTH; ++i)
            {
                genotype[i] = (LibStatics.getRandomizer().NextDouble() < 0.5) ? 0 : 1;
            }
        }

        public BinaryIndividual(BinaryIndividual other)
            : base(other)
        {}

        protected override void slotMutate(int i)
        {
            this.genotype[i] = 1 - this.genotype[i];
        }

        protected override void calcFit()
        {
            this.fitness = 0;
            for (int i = LENGTH - 1; i >= 0; i--)
            {
                this.fitness += (int)Math.Pow(2, LENGTH - i - 1) * genotype[i];
            }
        }

        public override string plotDisplay()
        {
            //return "Fitness:\t" + this.fitness;
            return this.fitness.ToString();
        }
    }
}
